package com.vhdadw.config;

import lombok.Data;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 自定义消息队列
 * 发送 关单消息 ——> 延迟exchange_>order,close.delay.queue ——> 死信exchange ——> order,close.queue
 */
@Configuration
@Data
public class RabbitMQConfig {

    /**
     * 消息转换器
     *
     * @return
     */
    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }

    //=============流量包处理，用户初始化福利====================

    /**
     * 交换机
     */
    public String trafficExchange = "traffic.event.exchange";

    /**
     * 用户注册 免费流量包新增  队列
     */
    private String trafficFreeInitQueue = "traffic.free_init.queue";

    /**
     * 用户注册 免费流量包新增  队列路由key
     */
    private String trafficFreeIniRoutingKey = "traffic.free_init.routing.key";


    /**
     * 创建交换机
     */
    @Bean
    public TopicExchange trafficEventExchange(){
        return new TopicExchange(trafficExchange,true,false);
    }

    /**
     * 创建队列
     */
    @Bean
    public Binding trafficFreeInitBinding(){
        return new Binding(trafficFreeInitQueue,Binding.DestinationType.QUEUE,trafficExchange,trafficFreeIniRoutingKey,null);
    }

    /**
     * 免费流量包队列
     */
    @Bean
    public Queue trafficFreeInitQueue(){
        return new Queue(trafficFreeInitQueue,true,false,false);
    }
}
